﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using XbdSoft.Contract;
using XbdSoft.Client;
using System.Diagnostics;

namespace XbdSoft
{
    public partial class XbdLoginForm : Form
    { 
        public XbdLoginForm()
        {
            InitializeComponent();
            HasLogin = false;
        }

        public bool HasLogin { get; set; }

        private void XbdLoginForm_Load(object sender, EventArgs e)
        {
            this.FillWithGradient(Color.AliceBlue, Color.LightBlue, LinearGradientMode.Vertical);
            foreach (Control control in Controls)
            {
                control.FillWithGradient(Color.Transparent, Color.Transparent, LinearGradientMode.Vertical);
            } 
        }

        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            using (var accountService = new ServiceObject<IAccountService>(Util.AccountServiceAddress))
            {
                if (accountService.Object.Login(UserNameTextBox.Text.Trim(), PasswordTextBox.Text))
                {
                    HasLogin = true;
                    Close();
                }
                else
                {
                    MessageBox.Show("用户名或密码错误。");
                }
            }
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        #region Link Click
        private void ForgotPasswordLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            using (var accountService = new ServiceObject<IAccountService>(Util.AccountServiceAddress))
            {
                Process.Start(accountService.Object.GetForgotPasswordUrl());
            }
        }

        private void SignUpLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

            using (var accountService = new ServiceObject<IAccountService>(Util.AccountServiceAddress))
            {
                Process.Start(accountService.Object.GetRegisterUrl());
            }
        }
        #endregion
        
    }
}
